package topday1_9.demo5;

/**
 * @Auther:小陈的Java
 * 方法声明的形参类型为父类类型，可以使用子类的对象作为实参调用该方法
 */
public class Demo1 {
    public void print(Animal animal) {
        animal.eat();
    }
    public static void main(String[] args) {
        Demo1 demo1 = new Demo1();
        Animal animal1 = new Tiger();
        Animal animal2 = new Sheep();
        demo1.print(animal1);
        demo1.print(animal2);
    }
}
class Animal {
    public void eat() {
        System.out.println("吃饭");
    }
}
class Tiger extends Animal{
    public void eat() {
        System.out.println("吃肉食");
    }
}
class Sheep extends Animal{
    public void eat() {
        System.out.println("吃草");
    }
}
